// 用户相关类型
export interface User {
  id: number
  username: string
  full_name?: string
  is_active: boolean
  last_login_at?: string
  created_at: string
  updated_at: string
}

// 数据层类型
export type DataLayer = 'TDS' | 'ODS' | 'DWD' | 'DWS' | 'DIM' | 'ADS'

// 监控表相关类型
export interface MonitoredTable {
  id: number
  table_name: string
  database_name: string
  layer: DataLayer
  description?: string
  is_active: boolean
  monitor_interval: number
  alert_threshold: number
  created_at: string
  updated_at: string
  is_monitored?: boolean
}

export interface TableStatistics {
  id: number
  table_id: number
  record_time: string
  row_count: number
  data_size?: number
  increment_count: number
  partition_count?: number
  avg_row_size?: number
  created_at: string
}

export interface TableSchema {
  id: number
  table_id: number
  column_name: string
  data_type: string
  is_nullable: boolean
  is_primary_key: boolean
  is_partition_key: boolean
  default_value?: string
  description?: string
  ordinal_position?: number
  created_at: string
  updated_at: string
}

// Flink作业相关类型
export type FlinkJobStatus = 'RUNNING' | 'FINISHED' | 'FAILED' | 'CANCELED' | 'REGISTERED' | 'MANUALLY_STOPPED'
export type FlinkJobHealthStatus = 'HEALTHY' | 'UNHEALTHY' | 'CRITICAL' | 'UNKNOWN'

export interface FlinkJob {
  id: number
  job_id?: string
  job_name: string
  module_name?: string
  jar_name: string
  jar_path: string
  entry_class: string
  program_args?: string
  last_status: FlinkJobStatus
  auto_recovery: boolean
  max_recovery_attempts: number
  recovery_attempts: number
  manual_stopped: boolean
  savepoint_interval: number
  last_savepoint_path?: string
  last_savepoint_time?: string
  description?: string
  created_at: string
  updated_at: string
  last_check_time?: string
  last_running_time?: string
  error_message?: string
  health_status: FlinkJobHealthStatus
  consecutive_failures: number
  total_failures: number
  version: number
}

export interface FlinkJobMapping {
  id: number
  module_name: string
  job_name: string
  entry_class: string
  jar_name: string
  jar_path: string
  default_parallelism: number
  default_program_args?: string
  is_active: boolean
  description?: string
  created_at: string
  updated_at: string
}

// 告警相关类型
export type AlertRuleType = 'data_volume' | 'data_delay' | 'job_failure' | 'custom' | 'flink_job'
export type AlertSeverity = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
export type AlertStatus = 'ACTIVE' | 'RESOLVED' | 'ACKNOWLEDGED'

export interface AlertRule {
  id: number
  name: string
  description?: string
  rule_type: AlertRuleType
  conditions: Record<string, any>
  severity: AlertSeverity
  is_active: boolean
  template_id?: number
  wechat_bot_id?: number
  created_at: string
  updated_at: string
}

export interface AlertHistory {
  id: number
  rule_id?: number
  alert_type: string
  title: string
  content?: string
  severity: AlertSeverity
  status: AlertStatus
  resource_type?: string
  resource_id?: string
  triggered_at: string
  resolved_at?: string
  acknowledged_by?: number
  acknowledged_at?: string
  notification_sent: boolean
}

export interface AlertTemplate {
  id: number
  name: string
  description?: string
  template_type: 'wechat' | 'email' | 'sms'
  title_template?: string
  content_template: string
  variables?: Record<string, any>
  is_active: boolean
  created_by?: number
  created_at: string
  updated_at: string
}

// 报表相关类型
export type ReportType = 'table'
export type ReportOutputFormat = 'CSV' | 'EXCEL' | 'HTML' | 'JSON'

export interface Report {
  id: number
  name: string
  description?: string
  report_type: ReportType
  query_sql?: string
  parameters?: Record<string, any>
  schedule_config?: Record<string, any>
  template_id?: number
  wechat_bot_id?: number
  is_active: boolean
  created_by?: number
  created_at: string
  updated_at: string
  output_format?: ReportOutputFormat
}

export interface ReportTemplate {
  id: number
  name: string
  description?: string
  template_type: 'csv' | 'excel' | 'html'
  template_content?: string
  header_template?: string
  row_template?: string
  footer_template?: string
  style_config?: Record<string, any>
  variables?: Record<string, any>
  is_active: boolean
  created_at: string
  updated_at: string
}

// 新增：报表执行记录
export type ReportExecutionStatus = 'PENDING' | 'RUNNING' | 'SUCCEEDED' | 'FAILED' | 'CANCELED'

export interface ReportExecution {
  id: number
  report_id: number
  report_name?: string
  status: ReportExecutionStatus
  started_at: string
  finished_at?: string
  duration_ms?: number
  row_count?: number
  output_format?: ReportOutputFormat
  output_uri?: string
  error_message?: string
  created_at?: string
  updated_at?: string
}

// 异步任务相关类型
export type TaskState = 'RUNNING' | 'FINISHED' | 'FAILED' | 'CANCELED'

export interface TaskRun {
  id: number
  query_id?: string
  task_name?: string
  create_time?: string
  finish_time?: string
  state: TaskState
  catalog?: string
  database_name?: string
  definition?: string
  expire_time?: string
  error_code?: number
  error_message?: string
  progress?: string
  extra_message?: string
  properties?: string
  created_at: string
}

// 数据库配置相关类型
export type DatabaseType = 'redis' | 'starrocks' | 'flink_mysql'

export interface DatabaseConfig {
  id: number
  name: string
  db_type: DatabaseType
  host: string
  port: number
  database_name?: string
  username?: string
  password?: string
  connection_pool_size: number
  connection_timeout: number
  read_timeout: number
  write_timeout: number
  ssl_enabled: boolean
  ssl_ca_file?: string
  ssl_cert_file?: string
  ssl_key_file?: string
  extra_params?: Record<string, any>
  description?: string
  is_active: boolean
  is_default: boolean
  created_at: string
  updated_at: string
}

// 微信机器人配置相关类型
export interface WechatBotConfig {
  id: number
  name: string
  webhook_url: string
  secret_key?: string
  is_active: boolean
  description?: string
  created_by?: number
  created_at: string
  updated_at: string
}

// 系统配置相关类型
export type ConfigType = 'string' | 'number' | 'boolean' | 'json'

export interface SystemConfig {
  id: number
  config_key: string
  config_value?: string
  config_type: ConfigType
  description?: string
  is_public: boolean
  category?: string
  created_at: string
  updated_at: string
}

// 操作日志相关类型
export interface OperationLog {
  id: number
  user_id?: number
  operation_type: string
  resource_type?: string
  resource_id?: string
  operation_details?: Record<string, any>
  ip_address?: string
  user_agent?: string
  created_at: string
}

// API响应类型
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
  timestamp: string
}

export interface PaginationResponse<T = any> {
  items: T[]
  pagination: {
    page: number
    size: number
    total: number
    pages: number
  }
}

// 分页参数
export interface PaginationParams {
  page?: number
  size?: number
}

// 通用查询参数
export interface QueryParams extends PaginationParams {
  [key: string]: any
}

// 仪表板相关类型
export interface LayerOverview {
  layer: DataLayer
  table_count: number
  total_rows: number
  total_size: number
  health_status: 'healthy' | 'warning' | 'error'
  last_update: string
}

export interface DashboardStats {
  total_tables: number
  total_data_size: number
  active_alerts: number
  running_jobs: number
  layers: LayerOverview[]
}

// 图表数据类型
export interface ChartDataPoint {
  time: string
  value: number
}

export interface ChartSeries {
  name: string
  data: ChartDataPoint[]
}

// 组件Props类型
export interface DashboardCardProps {
  title: string
  value: string | number
  unit?: string
  trend?: 'up' | 'down' | 'stable'
  trendValue?: string
  color?: string
  icon?: string
}

export interface TrendChartProps {
  data: ChartDataPoint[]
  title: string
  height?: number
  showLegend?: boolean
  color?: string[]
}

export interface TableListProps {
  data: any[]
  columns: any[]
  loading?: boolean
  pagination?: boolean
  searchable?: boolean
  filterable?: boolean
}

export interface AlertListProps {
  alerts: AlertHistory[]
  showActions?: boolean
  showFilter?: boolean
  maxHeight?: number
}

export interface TableDetailProps {
  tableId: string
  tableName: string
  database: string
  layer: string
  description?: string
  keyType: string
  keyColumns: string[]
  partitionStrategy: string
  partitionKey: string
  distributionStrategy: string
  distributionKey: string
  storageMedium: string
  partitionLiveNumber?: number
}

export interface SchemaTableProps {
  columns: TableSchema[]
  loading?: boolean
  searchable?: boolean
  exportable?: boolean
}

export interface TaskMonitorProps {
  tasks: TaskRun[]
  loading?: boolean
  showActions?: boolean
  onRetry?: (queryId: string) => void
  onCancel?: (queryId: string) => void
}

export interface TaskDetailProps {
  task: TaskRun
  visible: boolean
  onClose: () => void
  onRetry?: () => void
  onCancel?: () => void
}

export interface FlinkJobManagerProps {
  jobs: FlinkJob[]
  loading?: boolean
  onRegisterJob?: (jobData: any) => void
  onStopMonitor?: (jobId: string) => void
  onStartMonitor?: (jobId: string) => void
  onEditJob?: (jobId: string) => void
  onDeleteJob?: (jobId: string) => void
  onBatchImport?: (file: File) => void
  onEnableAllRecovery?: () => void
  onDisableAllRecovery?: () => void
}

export interface FlinkJobRegisterProps {
  visible: boolean
  onClose: () => void
  onSubmit: (jobData: any) => void
  initialData?: any
  isEdit?: boolean
}

export interface FlinkJobDetailProps {
  job: FlinkJob
  visible: boolean
  onClose: () => void
  onStopMonitor?: () => void
  onStartMonitor?: () => void
  onEditJob?: () => void
  onDeleteJob?: () => void
}

export interface FlinkJobRestartProps {
  visible: boolean
  onClose: () => void
  onSubmit: (config: any) => void
  availableModules: any[]
  runningJobs: any[]
}

export interface FlinkJobBatchStopProps {
  visible: boolean
  onClose: () => void
  onSubmit: (config: any) => void
  availableModules: any[]
  runningJobs: any[]
} 